/*
 * Created on Jan 26, 2009
 */
package com.mgmaps.app;

import javax.microedition.lcdui.*;
import ro.letsdoitromania.LDIRMidlet;
import com.mgmaps.tools.UITools;

public class PendingForm implements CommandListener {
  
  private static final PendingForm instance = new PendingForm();
  private volatile boolean cancelled;

  private Form form;
  private StringItem item;
  private Displayable previous;
  
  public static PendingForm getInstance() {
    return instance;
  }
  
  public boolean isCancelled() {
    return cancelled;
  }
  
  private PendingForm() {
  }

  public void show(Displayable prev, String title, String msg) {
    show(prev, title, msg, new Command[] { APPCommands.instance.cancelCommand });
  }
  
  public void show(Displayable prev, String title, String msg, Command[] commands) {
    previous = prev;
    if (item == null)
      item = new StringItem("", msg);
    else
      item.setText(msg);
    form = UITools.buildForm(form, title,
        new Item[] { item }, commands, this);
    Display.getDisplay(LDIRMidlet.instance).setCurrent(form);
    cancelled = false;
  }
  
  public void commandAction(Command cmd, Displayable disp) {
    cancelled = true;
    Display.getDisplay(LDIRMidlet.instance).setCurrent(previous);
  }

}
